package com.fenghongzhang.a18103.mvp.view.fragment;

import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.fenghongzhang.a18103.R;
import com.fenghongzhang.a18103.adapter.MeiziAdapter;
import com.fenghongzhang.a18103.entity.Meizi;
import com.fenghongzhang.a18103.mvp.contract.MeiziContract;
import com.fenghongzhang.a18103.mvp.model.MeiziModel;
import com.fenghongzhang.a18103.mvp.presenter.MeiziPresenter;
import com.fenghongzhang.lib.mvp.view.BaseFragment;
import com.fenghongzhang.lib.mvp.view.IFragment;
import com.fenghongzhang.lib.mvp.view.IView;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MeiziFragment extends BaseFragment<MeiziPresenter> implements IFragment, IView, MeiziContract.IMeiziView {



    private RecyclerView recyclerView;
    private MeiziAdapter meiziAdapter;
    private List<Meizi.DataBean> list;
    @Override
    public int bindLayout() {
        return R.layout.fragment_meizi;
    }

    @Override
    public void initView() {
        recyclerView = findViewById(R.id.fg_rv);
        list = new ArrayList<>();
        meiziAdapter = new MeiziAdapter(R.layout.rv_layout,list);
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        recyclerView.setAdapter(meiziAdapter);
    }

    @Override
    public void initData() {
        mPresenter = new MeiziPresenter(new MeiziModel(),this);
        mPresenter.getMeizi();
//        recyclerView.setAdapter();
    }

    @Override
    public void showToast(String s) {

    }

    @Override
    public void showMeizi(Meizi meizi) {
        Toast.makeText(getContext(),meizi.getData().size()+"", Toast.LENGTH_SHORT).show();
        List<Meizi.DataBean> data = meizi.getData();
        list.addAll(data);
        meiziAdapter.notifyDataSetChanged();
    }
}
